package nancal.mp.client

import nancal.mp.db.mongo.extend.getAppDeploySetting
import nancal.mp.db.mongo.mor
import nbcp.base.extend.AsString
import nbcp.http.event.HttpClientGatewayHostEvent
import nbcp.mvc.HttpContext
import org.springframework.context.annotation.Configuration
import org.springframework.context.event.EventListener

@Configuration
class HttpClientHostConfig {

    @EventListener
    fun hostListener(ev: HttpClientGatewayHostEvent) {
        var target = ev.request.name.split(".").first()
        if (target == "nexus") {
            var env_code = HttpContext.request.getAttribute("[env_code]").AsString();
            ev.requestHost = mor.dev.appDeploySetting.getAppDeploySetting(env_code).nexusServer.nexusHttpUrl
            return;
        }
        ev.requestHost = "//" + target + "-java"
    }
}